package com.zhouheng.springbootdesignpattern.singletonpattern;

/**
 * 懒汉式单例 double check演示
 *
 * @author 周恒
 * @date 20240607 13:47:18
 * @since v1.0
 */
public class DoubleCheckedLocking {

    private volatile static DoubleCheckedLocking slacker;

    private DoubleCheckedLocking() {

    }

    public static DoubleCheckedLocking getInstance() {
        if (slacker == null) {
            synchronized (DoubleCheckedLocking.class) {
                if (slacker == null) {
                    slacker = new DoubleCheckedLocking();
                    // 1开辟空间 2初始化对象信息 3返回对象的地址给引用
                }
            }
        }
        return slacker;
    }

}
